/*
Copyright (c) 2020-2022, Huawei Technologies Co., Ltd
 All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* Description: 3D图表可视化插件界面类
*/
#ifndef UI_SLT_WIDGET_H
#define UI_SLT_WIDGET_H

#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QWidget>
#include <QScrollArea>
#include <QPushButton>
#include <QWheelEvent>

#include <mgl2/qmathgl.h>

namespace chart_plugin {
class MathGL;
class UiSltWidget {
public:
    UiSltWidget() = default;
    ~UiSltWidget() = default;

    /*
     * 功能：设置界面元素，初始化界面
     * 输入参数：widget-QWidget窗口指针
     * 输出参数：无
     * 返回值：无
     */
    void SetupUi(QWidget *widget);

    /*
     * 功能：获取qMathGl窗口句柄
     * 输入参数：无
     * 输出参数：无
     * 返回值：QMathGL指针
     */
    QMathGL *GetQMathGl() const;

    /*
     * 功能：获取scrollAreaWidgetContents窗口句柄
     * 输入参数：无
     * 输出参数：无
     * 返回值：scrollAreaWidgetContents指针
     */
    QWidget *GetScrollAreaWidgetContents() const;

    /*
     * 功能：获取gridLayout布局器句柄
     * 输入参数：无
     * 输出参数：无
     * 返回值：gridLayout指针
     */
    QGridLayout *GetGridLayout() const;

    /*
     * 功能：获取restoreButton句柄
     * 输入参数：无
     * 输出参数：无
     * 返回值：restoreButton指针
     */
    QPushButton *GetRestoreButton() const;

private:
    /*
     * 功能：设置widget窗口UI
     * 输入参数：widget-窗口
     * 输出参数：无
     * 返回值：无
     */
    void SetupWidgetUi(QWidget &widget);

    /*
     * 功能：设置verticalLayout
     * 输入参数：verticalLayout-QVBoxLayout
     * 输出参数：无
     * 返回值：无
     */
    void SetupVerticalLayoutUi(QVBoxLayout &verticalLayout);

    /*
     * 功能：设置widgetMathGl的UI
     * 输入参数：widgetMathGl-QWidget
     * 输出参数：无
     * 返回值：无
     */
    void SetupWidgetMathGlUi(QWidget &widgetMathGl);

    /*
     * 功能：设置scrollArea的UI
     * 输入参数：scrollArea-QScrollArea
     * 输出参数：无
     * 返回值：无
     */
    void SetupScrollAreaUi(QScrollArea &scrollArea);

private:
    QVBoxLayout *verticalLayout { nullptr };
    MathGL *qMathGl { nullptr };

    QWidget *widgetMathGl { nullptr };
    QPushButton *restoreButton { nullptr };
    QScrollArea *scrollArea { nullptr };
    QWidget *scrollAreaWidgetContents { nullptr };
    QGridLayout *gridLayout { nullptr };
};

class MathGL : public QMathGL {
public:
    explicit MathGL(QWidget *parent = nullptr, Qt::WindowFlags flag = 0) : QMathGL(parent, flag) {}
    ~MathGL() override = default;

protected:
    void wheelEvent(QWheelEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    int32_t posX {};
    int32_t posY {};
    int32_t x {};
    int32_t y {};
};
}

#endif // UI_SLT_WIDGET_H
